package com.hulk.dryad.manage.boot.logger;

import com.hulk.dryad.common.constant.CommonConstants;
import net.dreamlu.mica.auto.annotation.AutoEnvPostProcessor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;

/**
 * logging 日志初始化
 *
 * @author hulk
 */
@AutoEnvPostProcessor
public class LoggingInitializer implements EnvironmentPostProcessor , Ordered {



	@Override
	public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {

		String appName = environment.getProperty(CommonConstants.SPRING_APP_NAME_KEY);
		// 读取系统配置的日志目录，默认为项目下 logs
		String logBase = environment.getProperty(CommonConstants.LOGGING_FILE_PATH, CommonConstants.DEFAULT_LOG_DIR);
		// 用于 spring boot admin 中展示日志
		System.setProperty(CommonConstants.LOGGING_FILE_NAME, String.format("%s/%s/debug.log", logBase, appName));
	}

	@Override
	public int getOrder() {
		return Ordered.LOWEST_PRECEDENCE;
	}

}
